package com.flowerplus.store.common.structure.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.flowerplus.store.R;


/**
 * Created by z on.
 * Des:
 * Date: 2017/3/8
 */

public abstract class ToolbarActivity extends LoadingActivity {

    protected Toolbar mToolbar;

    @Override
    protected int layoutResId() {
        return R.layout.activity_toolbar;
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setToolbar(mToolbar);
    }

    protected void setToolbar(Toolbar toolbar) {
        setSupportActionBar(toolbar);
        ActionBar bar =
                getSupportActionBar();
        bar.setDisplayHomeAsUpEnabled(true);
//        bar.setHomeAsUpIndicator(R.drawable.ic_back);
        bar.setHomeButtonEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void setToolbarTitle(String title) {
        mToolbar.setTitle(title);
        setSupportActionBar(mToolbar);
    }

}
